import sys
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
class Demo(QWidget):
    def __init__(self,parent=None):
        super(Demo,self).__init__(parent)
        self.i=1
        self.mypix()#显示不规则的图片
        self.timer=QTimer()
        self.timer.setInterval(500)
        self.timer.timeout.connect(self.timeChanged)
        self.timer.start()

    def mypix(self):
        self.update()
        if self.i==5:
            self.i=1
        self.mypic={1:'./images/left.png',2:'./images/up.png',3:'./images/right.png',4:'./images/down.png'}
        self.pix=QPixmap(self.mypic[self.i],'0',Qt.AvoidDither|Qt.ThresholdAlphaDither|Qt.ThresholdDither)
        self.resize(self.pix.size())
        self.setMask(self.pix.mask())
        self.dragPostion=None

    def mousePressEvent(self,event):
        #鼠标左键
        if event.button()==Qt.LeftButton:
            self.m_drag=True
            self.m_postion=QMouseEvent.globalPos()-self.pos()
            QMouseEvent.accept()
            self.setCursor(QCursor(Qt.OpenHandCursor))

    def mouseMoveEvent(self, event):
        #鼠标左键按下的同时移动鼠标
        if event.buttons() and Qt.LeftButton:
            self.move(QMouseEvent.globalPos(-self.m_postion))
            QMouseEvent.accept()
    def mouseReleaseEvent(self, event):
        if event.button()== Qt.LeftButton:
            self.m_drag=False
            self.setCursor(QCursor(Qt.ArrowCursor))
    def paintEvent(self, event):
        painter=QPainter(self)
        painter.drawPixmap(0,0,self.pix.width(),self.pix.height(),self.pix)

    def mouseDoubleClickEvent(self, event):
        if QMouseEvent.button()==1:
            self.i==1
            self.mypix()
    def timeChanged(self):
        self.i+=1
        self.mypix()


if __name__ == '__main__':
    app=QApplication(sys.argv)
    win=Demo()
    win.show()
    sys.exit(app.exec_())